const http = require("http");
let db = require("./db");
let qs = require("querystring");
http.createServer((req,res)=>{
    res.setHeader("Access-Control-Allow-Origin", "*")//跨域
    res.setHeader('Content-Type', 'text/html; charset=utf-8');//设置乱码
    if(req.url=="/favicon.ico"){
        return;
    }
    console.log(req.url);
    let str = req.url.split("?")[1];
    let data = qs.parse(str);
    let sql = `UPDATE user SET name = "${data.name}" WHERE id = ${data.id}`;
    db(sql,(err,result)=>{
        if(err){
            throw err
        }
        let data = {
            code:200,
            msg:"更新成功",
            data:result
        }
        res.end(JSON.stringify(data))
    })


}).listen(3003)
console.log(3003);